package com.eco.fanliapp.admin.controller.web;

import com.eco.fanliapp.admin.annotation.SysLogAnnotation;
import com.eco.fanliapp.admin.common.BaseController;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.entity.CommissionFreeze;
import com.eco.fanliapp.service.ICommissionFreezeService;
import com.eco.fanliapp.vo.CommissionFreezeInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/web/commissionFreeze")
public class CommissionFreezeController extends BaseController {

    @Autowired
    private ICommissionFreezeService commissionFreezeService;


    /**
     *  新写入数据库记录,web_commission_freeze
     *
     * @param record
     */
    @SysLogAnnotation(value = "保存资金冻结设置",userType = 2)
    @PostMapping("/insertOrUpdateCommissionFreeze")
    public ServerResponse insertOrUpdateCommissionFreeze(@RequestBody CommissionFreezeInfo record){
        return commissionFreezeService.insertOrUpdate(record);
    }

    /**
     *  根据指定主键获取一条数据库记录,web_commission_freeze
     * 获取到的adminitratorId  也就是管理员id  一一对应tableId
     */
    @GetMapping("/selectByTableId")
    public ServerResponse<CommissionFreeze> selectByTableId(){
        Integer adminitratorId = getAuthentication().getUserId();
        return commissionFreezeService.selectByPrimaryKey(adminitratorId);
    }

    /**
     * 根据主键修改资金冻结设置
     * @param record
     * @return
     */
    @SysLogAnnotation(value = "保存资金冻结设置",userType = 2)
    @PostMapping("/save")
    public ServerResponse save(@RequestBody CommissionFreeze record){
        Integer adminitratorId = getAuthentication().getUserId();
        record.setTableId(Integer.valueOf(adminitratorId));
        ServerResponse response = commissionFreezeService.updateByPrimaryKey(record);
        //刷新redis
        commissionFreezeService.selectByPrimaryKey(Integer.valueOf(adminitratorId), 0);
        return response;
    }
}
